package gosnoopers.fr;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Settings extends Activity {

	/********************** Called when the activity is first created. */
	ListView listView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.settings);

		TextView text_view_landing_page_header = (TextView) findViewById(R.id.text_view_landing_page_header);
		text_view_landing_page_header.setText("Settings");

		header();
		// Get ListView object from xml
		listView = (ListView) findViewById(R.id.list);

		// Defined Array values to show in ListView
		String[] values = new String[] { "Inscription", "Countries", "Language" };

		// Define a new Adapter
		// First parameter - Context
		// Second parameter - Layout for the row
		// Third parameter - ID of the TextView to which the data is written
		// Forth - the Array of data

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				R.layout.list_view_setting, R.id.text, values);

		// Assign adapter to ListView
		listView.setAdapter(adapter);

		// ListView Item Click Listener
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				// ListView Clicked item index
				int itemPosition = position;

				// ListView Clicked item value
				String itemValue = (String) listView
						.getItemAtPosition(position);

				// Show Alert

				if (itemPosition == 0) {

					if (MainActivity.userId.equalsIgnoreCase("0")) {

						Intent goToNextActivity = new Intent(
								getApplicationContext(), MainActivity.class);
						goToNextActivity.putExtra("inscription", 1);
						startActivity(goToNextActivity);
					} else {
						Intent inscription = new Intent(
								getApplicationContext(),
								InscriptionActivity.class);
						startActivity(inscription);
					}

				} else if (itemPosition == 1) {

					Intent goToNextActivity = new Intent(
							getApplicationContext(), Countries.class);
					startActivity(goToNextActivity);

				} else if (itemPosition == 2) {
					Intent langActivity = new Intent(getApplicationContext(), Language.class);
					startActivity(langActivity);
				} else {
					Toast.makeText(
							getApplicationContext(),
							"Position :" + itemPosition + "  ListItem : "
									+ itemValue, Toast.LENGTH_LONG).show();
				}

				/*
				 * Intent goToNextActivity = new Intent(getApplicationContext(),
				 * Countries.class); startActivity(goToNextActivity);
				 */

			}

		});

	}
	//******************************HEADER***************************************
	public void header() {
		ImageView btn_setting = (ImageView) findViewById(R.id.image_setting);
		btn_setting.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent goToNextActivity = new Intent(getApplicationContext(),
						Settings.class);
				startActivity(goToNextActivity);
			}
		});

		/**
		 * Kiem user da dang nhap hay chua 1. hein thi icon user 2. hien thi
		 * icon add victimes
		 */
		ImageView image_open_left_navigation = (ImageView) findViewById(R.id.image_open_left_navigation);
		ImageView icon_header_form = (ImageView) findViewById(R.id.icon_header_form);
		if (MainActivity.userId.equalsIgnoreCase("0")) {
			image_open_left_navigation.setVisibility(View.VISIBLE);
			icon_header_form.setVisibility(View.GONE);
		} else {
			image_open_left_navigation.setVisibility(View.GONE);
			icon_header_form.setVisibility(View.VISIBLE);
		}

		image_open_left_navigation.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent goToNextActivity = new Intent(getApplicationContext(),
						MainActivity.class);
				startActivity(goToNextActivity);
			}
		});

		icon_header_form.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent goToNextActivity = new Intent(getApplicationContext(),
						FormFirst.class);
				startActivity(goToNextActivity);
			}
		});
	}
	//***********************on key down****************************
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// Log.d("keyCode","sdsdf "+keyCode);
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// your code
			// Log.d("BBBBBBBBBBBBBBBB",MainActivity.userId);

			Intent goToNextActivity = new Intent(getApplicationContext(),
					HomePage.class);
			startActivity(goToNextActivity);
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

}